package com.lby.psychology.config;

import org.springframework.context.annotation.Configuration;

@Configuration
public class QQLoginConfig {
    /**
     * oauth2 认证回调返回得code
     */
    public final String CODE = "code";


    /**
     * oauth2 获取token得返回类型
     */
    public final String FMT = "json";

    /**
     * grant_type 授权码模式
     */
    public final String GRANT_TYPE = "authorization_code";

    /**
     * client_id 由腾讯提供(即AppId)
     */
    public final String CLIENT_ID = "101583722";

    /**
     * client_secret 由腾讯提供(即App Key)
     */
    public final String CLIENT_SECRET = "e7a157c1c7228e7d08c332b3d6afeedc";


    /**
     * redirect_uri 回调地址，这里我们随便写个地址 只要是本项目就好，被filter直接拦截住
     */
    public final String REDIRECT_URI = "https://codegg.cn/qqlogin/success";

    /**
     * 获取 access_token_url 的 url
     */
    public final String ACCESS_TOKEN_URL = "https://graph.qq.com/oauth2.0/token";


    /**
     * 获取 OpenID url地址
     */
    public final String OPENID_URL = "https://graph.qq.com/oauth2.0/me?access_token=%s&fmt=%s";


    /**
     * 获取 token 的地址拼接
     */
    public final String TOKEN_ACCESS_API = "%s?grant_type=%s&client_id=%s&client_secret=%s&code=%s&redirect_uri=%s&fmt=%s";

    /**
     * 获取用户信息
     */
    public final String USER_INFO_URL = "https://graph.qq.com/user/get_user_info?access_token=%s&oauth_consumer_key=%s&openid=%s";



    public String getAccessTokenUrl(String code) {
        return String.format(TOKEN_ACCESS_API,ACCESS_TOKEN_URL,GRANT_TYPE,CLIENT_ID,CLIENT_SECRET,code,REDIRECT_URI,FMT);
    }

    public String getOpenIdUrl(String accessToken) {
        return String.format(OPENID_URL,accessToken,FMT);
    }

    public String getUserInfoUrl(String openId, String accessToken) {
        return String.format(USER_INFO_URL,accessToken,CLIENT_ID,openId);
    }
}
